/*
* glTF 2.0 Model Render - File Open Dialog 
*
* Copyright (C) 2021 by Xuanyi Technology
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#include <string>
#include <vector>

std::vector<std::string> openFileDialog(char const * const aTitle, char const * const aDefaultPathAndFile)
{

   int i;
   std::vector<std::string> fileList;
   // Create a File Open Dialog class.
   NSOpenPanel* openDlg = [NSOpenPanel openPanel];
   [openDlg setLevel:CGShieldingWindowLevel()];
   // Set array of file types

   NSMutableArray * fileTypesArray = [NSMutableArray arrayWithObjects:@"gltf", @"glb", nil];

   // Enable options in the dialog.
   [openDlg setCanChooseFiles:YES];
   [openDlg setAllowedFileTypes:fileTypesArray];
   [openDlg setAllowsMultipleSelection:TRUE];
   [openDlg setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:aDefaultPathAndFile ] ] ];

   // Display the dialog box. If the OK pressed,
   // process the files.
   if ( [openDlg runModal] == NSModalResponseOK ) {
      // Gets list of all files selected
      NSArray *files = [openDlg URLs];
      // Loop through the files and process them.
      for(i = 0; i < [files count]; i++) {
         // Do something with the filename.
        fileList.push_back(std::string([[[files objectAtIndex:i] path] UTF8String]));
         }
      }
   return fileList;
}
